package br.uefs.ecomp.myBook.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import br.uefs.ecomp.myBook.control.UserController;
import br.uefs.ecomp.myBook.model.Profile;

@SuppressWarnings("serial")
public class ProfilePanel extends JPanel implements ActionListener {

	private Profile perfil;
	private ActionListener listener;

	public ProfilePanel(ActionListener listener) {
		UserController c = UserController.getInstance();
		perfil = c.getVisitedUser();
		initializeComponents();
		this.listener = listener;
	}

	private void initializeComponents() {

		setLayout(new BorderLayout());
		
		JPanel centerPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
		
		JPanel tempPanel = new JPanel();
		tempPanel.setLayout(new BoxLayout(tempPanel, BoxLayout.Y_AXIS));
		tempPanel.setPreferredSize(new Dimension(400, 200));		
		
		addFields("Nome", perfil.getName(), tempPanel, Color.white);
		addFields("Cidade", perfil.getCity(), tempPanel, Color.gray);
		addFields("Telefone", perfil.getPhone(), tempPanel, Color.white);
		addFields("E-mail", perfil.getEmail(), tempPanel, Color.gray);
		addFields("Nascimento", perfil.getBirthDate(), tempPanel, Color.white);
		
		
		add(centerPanel, BorderLayout.CENTER);
		centerPanel.add(tempPanel);
		
		JLabel title = new MyBookTitle("Perfil de "+perfil.getName().split(" ")[0], 22);
		add(title, BorderLayout.NORTH);
		
	}
	
	private void addFields(String t1, String t2, JPanel p, Color c){
		JLabel l1, l2;
		l1 = new JLabel(t1, JLabel.CENTER);
		l2 = new JLabel(t2, JLabel.CENTER);
		
		l1.setPreferredSize(new Dimension(100, 20));
		l1.setBackground(new Color((int)(c.getRed()*0.7), (int)(c.getGreen()*0.7), (int)(c.getBlue()*0.7)));
		l1.setOpaque(true);
		
		JPanel tempPanel = new JPanel(new BorderLayout());
		tempPanel.add(l1, BorderLayout.WEST);
		tempPanel.add(l2, BorderLayout.CENTER);
		tempPanel.setBackground(c);
		
		p.add(tempPanel);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO: Algo. Ou nada.	
		listener.actionPerformed(e);
	}

}
